package com.hua.store.service.impl;

import com.hua.store.dao.UserDao;
import com.hua.store.dao.impl.UserDaoImpl;
import com.hua.store.domin.User;
import com.hua.store.service.UserService;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {

    @Override
    public void userRegister(User user) throws SQLException {
        UserDao dao = new UserDaoImpl();
        dao.userRegister(user);
    }

    @Override
    public User userActive(String code) {
        UserDao dao = new UserDaoImpl();
        User user = dao.userActive(code);
        return user;
    }

    @Override
    public void userActiveLate(User user) {
        UserDao dao = new UserDaoImpl();
        dao.userActiveLate(user);
    }

    @Override
    public User userLogin(User user) throws SQLException {
        UserDao dao = new UserDaoImpl();
        User user1 = dao.userLogin(user);
        if (user1 == null) {
            throw new RuntimeException("用户与密码不匹配");
        } else if (user1.getState() == 0) {
            throw new RuntimeException("用户未激活");
        }else {
            return user1;
        }
    }

    @Override
    public boolean checkUser(String username) throws SQLException {
        UserDao dao = new UserDaoImpl();
        User user = dao.checkUser(username);
        if (user!=null){
            return true;
        }else {
            return false;
        }
    }
}
